<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Role_List</title>
</head>
<body>
	<div>
		<table>
			<tbody>
				<div style="height:25px;background:cornflowerblue;">
					<input type="button" value="角色添加" style="float:right;" onclick="window.open('${pageContext.request.contextPath}/role_to_add','mainFrame')"/>
				</div>
				<tr>
					<td>编号</td>
					<td>角色名</td>
					<td>角色简介</td>
					<td>操作</td>
				</tr>
				<c:forEach var="roles" items="${sessionScope.role_list }" varStatus="index">
					<tr>
						<td>${roles.roleId }</td>
						<td>${roles.roleName }</td>
						<td>${roles.roleAbstract }</td>
						<td>
							<input type="button" value="编辑" onclick="javascript:window.location.href='${pageContext.request.contextPath}/role_to_edit?roleId=${roles.roleId}'"/>
							<input type="button" value="删除" onclick="role_delete('${roles.roleId}');"/>
						</td>
					</tr>
				</c:forEach>
			</tbody>
		</table>
	</div>
</body>
<script src="${pageContext.request.contextPath }/js/jquery-1.11.0.js" type="text/javascript"></script>
<script type="text/javascript">
	function role_delete(roleId){
		var flag = confirm("是否删除该条记录！？");
		if(flag){
			$.ajax({
				type:'post',
				url:'role_delete',
				data:'roleId='+roleId,
				success:function (data){
					if(data.role_delete_msg != undefined){
						alert(data.role_delete_msg);
					}else{
						window.location.href='role_list';	
					}
				},
				error:function (){
					alert("执行失败，请联系管理员。");
				}
			});
		}else{
			alert("请谨慎操作！");
		}
	}
</script>
</html>